<template>
  <el-dialog :title="'请选择房间'" :close-on-click-modal="false" :visible.sync="visible" :append-to-body="true">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="房号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t('Common.Query') }}</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;">
      <el-table-column type="selection" header-align="center" align="center" width="50">
      </el-table-column>

      <el-table-column prop="fpname" header-align="center" align="center" label="整栋"></el-table-column>
      <el-table-column prop="fname" header-align="center" align="center" label="楼层"></el-table-column>
      <el-table-column prop="roomName" header-align="center" align="center" label="房型"></el-table-column>
      <el-table-column prop="roomPrice" header-align="center" align="center" label="价格"></el-table-column>
      <el-table-column prop="roomSignNum" header-align="center" align="center" label="房号">
        <!--   <template slot-scope="scope">
              <span>{{ scope.row.roomSign }}{{ scope.row.roomNum }}</span>
            </template> -->
      </el-table-column>
      <el-table-column prop="roomSignNum" header-align="center" align="center" label="状态">
          <template slot-scope="scope">
            <!-- 类型（0空净1空脏2住净3住脏4维修5锁房）-->
            <span v-if="scope.row.type == 0">空净房</span>
            <span v-if="scope.row.type == 1">空脏房</span>
          </template>
      </el-table-column>
      <el-table-column prop="roomDesc" header-align="center" align="center" label="描述">
        <template slot-scope="scope">
          <span v-if="scope.row.roomDesc">{{ scope.row.roomDesc}}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination style="text-align: right;margin-top: 10px;" @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
      :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="addLianfangSumbit()" :disabled="this.dataListSelections.length == 0">确定</el-button>
    </span>
  </el-dialog>
</template>


<script>
  export default {
    data() {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        singleId: 0,
        pageSize: 8,
        totalPage: 0,
        dataListLoading: false,
        visible: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {

    },
    methods: {
      init(singleId) {
        this.singleId = singleId
        this.visible = true;
        this.$nextTick(() => {
          this.getDataList()
        })
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelfloorroom/list2'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      addLianfangSumbit() {
        var ids = [];
        this.dataListSelections.forEach(item=>{
          ids.push(item.id)
        })
        if (ids.length == 0) {
          this.$message.error("请选择房间")
          return false
        }
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelfloorroomcheckinsingle/addLianfang`),
          method: 'post',
          data: this.$http.adornData({
            singleId: this.singleId,
            ids:ids.join(",")
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.visible = false
            this.$nextTick(() => {
              this.$emit('refreClosing');
            });
            this.$message({
              message: this.$t('Common.OperationSuccessful'),
              type: 'success',
              duration: 1500,
              onClose: () => {

              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      }
    }
  }
</script>
